import book.Library;
import factory.AdmainFactory;
import factory.IFactoryUser;
import factory.NormalFactory;
import user.ProxyUser;
import user.User;

import java.util.Scanner;
import java.util.concurrent.Callable;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.06.14
 *Time:23:26
 */
public class LibrarySystem {
    //实现选择
    public ProxyUser selectProxyRole(ProxyUser admin,ProxyUser normal1,ProxyUser normal2){
        System.out.println("选择对象：1.管理员刘备 2.普通用户关羽 3.普通用户张飞");
        System.out.print("请选择：");
        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();
        //选择
        ProxyUser current = null;
        switch (choice){
            case 1:
                current = admin;
                break;
            case 2:
                current = normal1;break;
            case 3:
                current = normal2;break;
            case 0:
                System.out.println("退出系统！");
                break;
            default:
                System.out.println("非法输入！");
        }
        return current;
    }

    public static void main(String[] args) {
        //管理员
       IFactoryUser iFactoryAdm = new AdmainFactory();
       User administrator = iFactoryAdm.creater("刘备",123);
       //普通用户
        IFactoryUser iFactoryNor = new NormalFactory();
        User normalUser1 = iFactoryNor.creater("关羽",234);
        User normalUser2 = iFactoryNor.creater("张飞",345);
        //代理对象
        ProxyUser proxyUser0 = new ProxyUser(administrator);
        ProxyUser proxyUser1 = new ProxyUser(normalUser1);
        ProxyUser proxyUser2 = new ProxyUser(normalUser2);

        //选项代理对象
        LibrarySystem librarySystem = new LibrarySystem();
        ProxyUser currentProxyRole = librarySystem.selectProxyRole(proxyUser0,proxyUser1,proxyUser2);

        //代理功能
        while(true){
            //1.打印代理对象的菜单
           int choice = currentProxyRole.getRealUser().display();
           //2.选择功能
           currentProxyRole.handleOperation(choice);

          }
    }

}
